package com.cjg.netCode;


import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;

public class netUDP {
    public static void main(String[] args) throws Exception {
        //udp 不需要写服务器
        DatagramSocket datagramSocket = new DatagramSocket();
        String msg ="hello,msg";
        //发送给谁
        InetAddress byName = InetAddress.getByName("127.0.0.1");


        DatagramPacket packet = new DatagramPacket(msg.getBytes(),0,msg.getBytes().length,byName,7777);
        //发送包
        datagramSocket.send(packet);

        //关闭
        datagramSocket.close();
    }
}
